home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / maskbits.h,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  18.1 KB  |  619 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.57.51;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* Combined Purdue/PurduePlus patches, level 2.1, 1/24/89 */
  27. /***********************************************************
  28. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  29. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  30.  
  31.                         All Rights Reserved
  32.  
  33. Permission to use, copy, modify, and distribute this software and its
  34. documentation for any purpose and without fee is hereby granted,
  35. provided that the above copyright notice appear in all copies and that
  36. both that copyright notice and this permission notice appear in
  37. supporting documentation, and that the names of Digital or MIT not be
  38. used in advertising or publicity pertaining to distribution of the
  39. software without specific, written prior permission.
  40.  
  41. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  42. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  43. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  44. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  45. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  46. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  47. SOFTWARE.
  48.  
  49. ******************************************************************/
  50. /* $XConsortium: maskbits.h,v 1.21 89/11/13 09:36:56 rws Exp $ */
  51. #include "X.h"
  52. #include "Xmd.h"
  53. #include "servermd.h"
  54.  
  55. extern int starttab[];
  56. extern int endtab[];
  57. extern unsigned partmasks[32][32];
  58. extern int rmask[];
  59. extern int mask[];
  60.  
  61.  
  62. /* the following notes use the following conventions:
  63. SCREEN LEFT                SCREEN RIGHT
  64. in this file and maskbits.c, left and right refer to screen coordinates,
  65. NOT bit numbering in registers.
  66.  
  67. starttab[n]
  68.     bits[0,n-1] = 0    bits[n,31] = 1
  69. endtab[n] =
  70.     bits[0,n-1] = 1    bits[n,31] = 0
  71.  
  72. startpartial[], endpartial[]
  73.     these are used as accelerators for doing putbits and masking out
  74. bits that are all contained between longword boudaries.  the extra
  75. 256 bytes of data seems a small price to pay -- code is smaller,
  76. and narrow things (e.g. window borders) go faster.
  77.  
  78. the names may seem misleading; they are derived not from which end
  79. of the word the bits are turned on, but at which end of a scanline
  80. the table tends to be used.
  81.  
  82. look at the tables and macros to understand boundary conditions.
  83. (careful readers will note that starttab[n] = ~endtab[n] for n != 0)
  84.  
  85. -----------------------------------------------------------------------
  86. these two macros depend on the screen's bit ordering.
  87. in both of them x is a screen position.  they are used to
  88. combine bits collected from multiple longwords into a
  89. single destination longword, and to unpack a single
  90. source longword into multiple destinations.
  91.  
  92. SCRLEFT(dst, x)
  93.     takes dst[x, 32] and moves them to dst[0, 32-x]
  94.     the contents of the rest of dst are 0 ONLY IF
  95.     dst is UNSIGNED.
  96.     this is a right shift on LSBFirst (forward-thinking)
  97.     machines like the VAX, and left shift on MSBFirst
  98.     (backwards) machines like the 680x0 and pc/rt.
  99.  
  100. SCRRIGHT(dst, x)
  101.     takes dst[0,x] and moves them to dst[32-x, 32]
  102.     the contents of the rest of dst are 0 ONLY IF
  103.     dst is UNSIGNED.
  104.     this is a left shift on LSBFirst, right shift
  105.     on MSBFirst.
  106.  
  107.  
  108. the remaining macros are cpu-independent; all bit order dependencies
  109. are built into the tables and the two macros above.
  110.  
  111. maskbits(x, w, startmask, endmask, nlw)
  112.     for a span of width w starting at position x, returns
  113. a mask for ragged bits at start, mask for ragged bits at end,
  114. and the number of whole longwords between the ends.
  115.  
  116. maskpartialbits(x, w, mask)
  117.     works like maskbits(), except all the bits are in the
  118.     same longword (i.e. (x&0x1f + w) <= 32)
  119.  
  120. mask32bits(x, w, startmask, endmask, nlw)
  121.     as maskbits, but does not calculate nlw.  it is used by
  122.     mfbGlyphBlt to put down glyphs <= 32 bits wide.
  123.  
  124. -------------------------------------------------------------------
  125.  
  126. NOTE
  127.     any pointers passe to the following 4 macros are
  128.     guranteed to be 32-bit aligned.
  129.     The only non-32-bit-aligned references ever made are
  130.     to font glyphs, and those are made with getleftbits()
  131.     and getshiftedleftbits (qq.v.)
  132.  
  133. getbits(psrc, x, w, dst)
  134.     starting at position x in psrc (x < 32), collect w
  135.     bits and put them in the screen left portion of dst.
  136.     psrc is a longword pointer.  this may span longword boundaries.
  137.     it special-cases fetching all w bits from one longword.
  138.  
  139.     +--------+--------+        +--------+
  140.     |    | m |n|      |    ==>     | m |n|  |
  141.     +--------+--------+        +--------+
  142.         x      x+w            0     w
  143.     psrc     psrc+1            dst
  144.             m = 32 - x
  145.             n = w - m
  146.  
  147.     implementation:
  148.     get m bits, move to screen-left of dst, zeroing rest of dst;
  149.     get n bits from next word, move screen-right by m, zeroing
  150.          lower m bits of word.
  151.     OR the two things together.
  152.  
  153. putbits(src, x, w, pdst)
  154.     starting at position x in pdst, put down the screen-leftmost
  155.     w bits of src.  pdst is a longword pointer.  this may
  156.     span longword boundaries.
  157.     it special-cases putting all w bits into the same longword.
  158.  
  159.     +--------+            +--------+--------+
  160.     | m |n|  |        ==>    |    | m |n|      |
  161.     +--------+            +--------+--------+
  162.     0     w                     x     x+w
  163.     dst                pdst     pdst+1
  164.             m = 32 - x
  165.             n = w - m
  166.  
  167.     implementation:
  168.     get m bits, shift screen-right by x, zero screen-leftmost x
  169.         bits; zero rightmost m bits of *pdst and OR in stuff
  170.         from before the semicolon.
  171.     shift src screen-left by m, zero bits n-32;
  172.         zero leftmost n bits of *(pdst+1) and OR in the
  173.         stuff from before the semicolon.
  174.  
  175. putbitsrop(src, x, w, pdst, ROP)
  176.     like putbits but calls DoRop with the rasterop ROP (see mfb.h for
  177.     DoRop)
  178.  
  179. putbitsrrop(src, x, w, pdst, ROP)
  180.     like putbits but calls DoRRop with the reduced rasterop ROP
  181.     (see mfb.h for DoRRop)
  182.  
  183. -----------------------------------------------------------------------
  184.     The two macros below are used only for getting bits from glyphs
  185. in fonts, and glyphs in fonts are gotten only with the following two
  186. mcros.
  187.     You should tune these macros toyour font format and cpu
  188. byte ordering.
  189.  
  190. NOTE
  191. getleftbits(psrc, w, dst)
  192.     get the leftmost w (w<=32) bits from *psrc and put them
  193.     in dst.  this is used by the mfbGlyphBlt code for glyphs
  194.     <=32 bits wide.
  195.     psrc is declared (unsigned char *)
  196.  
  197.     psrc is NOT guaranteed to be 32-bit aligned.  on  many
  198.     machines this will cause problems, so there are several
  199.     versions of this macro.
  200.  
  201.     this macro is called ONLY for getting bits from font glyphs,
  202.     and depends on the server-natural font padding.
  203.  
  204.     for blazing text performance, you want this macro
  205.     to touch memory as infrequently as possible (e.g.
  206.     fetch longwords) and as efficiently as possible
  207.     (e.g. don't fetch misaligned longwords)
  208.  
  209. getshiftedleftbits(psrc, offset, w, dst)
  210.     used by the font code; like getleftbits, but shifts the
  211.     bits SCRLEFT by offset.
  212.     this is implemented portably, calling getleftbits()
  213.     and SCRLEFT().
  214.     psrc is declared (unsigned char *).
  215. */
  216.  
  217. #if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
  218. #define LONG2CHARS(x) (x)
  219. #else
  220. /*
  221.  *  the unsigned case below is for compilers like
  222.  *  the Danbury C and i386cc
  223.  */
  224. #define LONG2CHARS( x ) ( ( ( ( x ) & 0x000000FF ) << 0x18 ) \
  225.                       | ( ( ( x ) & 0x0000FF00 ) << 0x08 ) \
  226.                       | ( ( ( x ) & 0x00FF0000 ) >> 0x08 ) \
  227.                       | ( ( ( x ) & (unsigned long)0xFF000000 ) >> 0x18 ) )
  228. #endif
  229.  
  230. #ifdef STRICT_ANSI_SHIFT
  231. #define SHL(x,y)    ((y) >= 32 ? 0 : LONG2CHARS(LONG2CHARS(x) << (y)))
  232. #define SHR(x,y)    ((y) >= 32 ? 0 : LONG2CHARS(LONG2CHARS(x) >> (y)))
  233. #else
  234. #define SHL(x,y)    LONG2CHARS(LONG2CHARS(x) << (y))
  235. #define SHR(x,y)    LONG2CHARS(LONG2CHARS(x) >> (y))
  236. #endif
  237.  
  238. #if (BITMAP_BIT_ORDER == MSBFirst)    /* pc/rt, 680x0 */
  239. #define SCRLEFT(lw, n)    SHL((unsigned int)(lw),(n))
  240. #define SCRRIGHT(lw, n)    SHR((unsigned int)(lw),(n))
  241. #else                    /* vax, intel */
  242. #define SCRLEFT(lw, n)    SHR((lw),(n))
  243. #define SCRRIGHT(lw, n)    SHL((lw),(n))
  244. #endif
  245.  
  246. #define maskbits(x, w, startmask, endmask, nlw) \
  247.     startmask = starttab[(x)&0x1f]; \
  248.     endmask = endtab[((x)+(w)) & 0x1f]; \
  249.     if (startmask) \
  250.     nlw = (((w) - (32 - ((x)&0x1f))) >> 5); \
  251.     else \
  252.     nlw = (w) >> 5;
  253.  
  254. #define maskpartialbits(x, w, mask) \
  255.     mask = partmasks[(x)&0x1f][(w)&0x1f];
  256.  
  257. #define mask32bits(x, w, startmask, endmask) \
  258.     startmask = starttab[(x)&0x1f]; \
  259.     endmask = endtab[((x)+(w)) & 0x1f];
  260.  
  261. #ifdef __GNUC__
  262. #ifdef vax
  263. #define FASTGETBITS(psrc,x,w,dst) \
  264.     asm ("extzv %1,%2,%3,%0" \
  265.      : "=g" (dst) \
  266.      : "g" (x), "g" (w), "m" (*(char *)(psrc)))
  267. #define getbits(psrc,x,w,dst) FASTGETBITS(psrc,x,w,dst)
  268.  
  269. #define FASTPUTBITS(src, x, w, pdst) \
  270.     asm ("insv %3,%1,%2,%0" \
  271.      : "=m" (*(char *)(pdst)) \
  272.      : "g" (x), "g" (w), "g" (src))
  273. #define putbits(src, x, w, pdst) FASTPUTBITS(src, x, w, pdst)
  274. #endif /* vax */
  275. #ifdef mc68020
  276. #define FASTGETBITS(psrc, x, w, dst) \
  277.     asm ("bfextu %3{%1:%2},%0" \
  278.     : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
  279.  
  280. #define getbits(psrc,x,w,dst) \
  281. { \
  282.     FASTGETBITS(psrc, x, w, dst);\
  283.     dst = SHL(dst,(32-(w))); \
  284. }
  285.  
  286. #define FASTPUTBITS(src, x, w, pdst) \
  287.     asm ("bfins %3,%0{%1:%2}" \
  288.      : "=o" (*(char *)(pdst)) \
  289.      : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
  290.  
  291. #define putbits(src, x, w, pdst) FASTPUTBITS(SHR((src),32-(w)), x, w, pdst)
  292.  
  293. #endif /* mc68020 */
  294. #endif /* __GNUC__ */
  295.  
  296. /*  The following flag is used to override a bugfix for sun 3/60+CG4 machines,
  297.  */
  298.  
  299. /*  We don't need to be careful about this unless we're dealing with sun3's 
  300.  *  We will default its usage for those who do not know anything, but will
  301.  *  override its effect if the machine doesn't look like a sun3 
  302.  */
  303. #if !defined(mc68020) || !defined(sun)
  304. #define NO_3_60_CG4
  305. #endif
  306.  
  307. /* This is gross.  We want to #define u_putbits as something which can be used
  308.  * in the case of the 3/60+CG4, but if we use /bin/cc or are on another
  309.  * machine type, we want nothing to do with u_putbits.  What a hastle.  Here
  310.  * I used slo_putbits as something which either u_putbits or putbits could be
  311.  * defined as.
  312.  *
  313.  * putbits gets it iff it is not already defined with FASTPUTBITS above.
  314.  * u_putbits gets it if we have FASTPUTBITS (putbits) from above and have not
  315.  *     overridden the NO_3_60_CG4 flag.
  316.  */
  317.  
  318. #define slo_putbits(src, x, w, pdst) \
  319. { \
  320.     register int n = (x)+(w)-32; \
  321.     \
  322.     if (n <= 0) \
  323.     { \
  324.     register int tmpmask; \
  325.     maskpartialbits((x), (w), tmpmask); \
  326.     *(pdst) = (*(pdst) & ~tmpmask) | \
  327.         (SCRRIGHT((unsigned) src, x) & tmpmask); \
  328.     } \
  329.     else \
  330.     { \
  331.     *(pdst) = (*(pdst) & endtab[x]) | (SCRRIGHT((unsigned) (src), x)); \
  332.     (pdst)[1] = ((pdst)[1] & starttab[n]) | \
  333.         (SCRLEFT((unsigned) src, 32-(x)) & endtab[n]); \
  334.     } \
  335. }
  336.  
  337. #if defined(putbits) && !defined(NO_3_60_CG4)
  338. #define u_putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
  339. #else
  340. #define u_putbits(src, x, w, pdst) putbits(src, x, w, pdst)
  341. #endif
  342.  
  343. #if !defined(putbits) 
  344. #define putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
  345. #endif
  346.  
  347. /* Now if we have not gotten any really good bitfield macros, try some
  348.  * moderately fast macros.  Alas, I don't know how to do asm instructions
  349.  * without gcc.
  350.  */
  351.  
  352. #ifndef getbits
  353. #define getbits(psrc, x, w, dst) \
  354. { \
  355.     dst = SCRLEFT((unsigned) *(psrc), (x)); \
  356.     if ( ((x) + (w)) > 32) \
  357.     dst |= (SCRRIGHT((unsigned) *((psrc)+1), 32-(x))); \
  358. }
  359. #endif
  360.  
  361. /*  We have to special-case putbitsrop because of 3/60+CG4 combos
  362.  */
  363.  
  364. #define u_putbitsrop(src, x, w, pdst, rop) \
  365. {\
  366.     register int t1, t2; \
  367.     register int n = (x)+(w)-32; \
  368.     \
  369.     t1 = SCRRIGHT((src), (x)); \
  370.     DoRop(t2, rop, t1, *(pdst)); \
  371.     \
  372.     if (n <= 0) \
  373.     { \
  374.     register int tmpmask; \
  375.     \
  376.     maskpartialbits((x), (w), tmpmask); \
  377.     *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
  378.     } \
  379.     else \
  380.     { \
  381.     int m = 32-(x); \
  382.     *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
  383.     t1 = SCRLEFT((src), m); \
  384.     DoRop(t2, rop, t1, (pdst)[1]); \
  385.     (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
  386.     } \
  387. }
  388.  
  389. /* If our getbits and putbits are FAST enough,
  390.  * do this brute force, it's faster
  391.  */
  392.  
  393. #if defined(FASTPUTBITS) && defined(FASTGETBITS) && defined(NO_3_60_CG4)
  394. #if (BITMAP_BIT_ORDER == MSBFirst)
  395. #define putbitsrop(src, x, w, pdst, rop) \
  396. { \
  397.   register int _tmp, _tmp2; \
  398.   FASTGETBITS(pdst, x, w, _tmp); \
  399.   _tmp2 = SCRRIGHT(src, 32-(w)); \
  400.   DoRop(_tmp, rop, _tmp2, _tmp) \
  401.   FASTPUTBITS(_tmp, x, w, pdst); \
  402. }
  403. #define putbitsrrop(src, x, w, pdst, rop) \
  404. { \
  405.   register int _tmp, _tmp2; \
  406.  \
  407.   FASTGETBITS(pdst, x, w, _tmp); \
  408.   _tmp2 = SCRRIGHT(src, 32-(w)); \
  409.   _tmp= DoRRop(rop, _tmp2, _tmp); \
  410.   FASTPUTBITS(_tmp, x, w, pdst); \
  411. }
  412. #undef u_putbitsrop
  413. #else
  414. #define putbitsrop(src, x, w, pdst, rop) \
  415. { \
  416.   register int _tmp; \
  417.   FASTGETBITS(pdst, x, w, _tmp); \
  418.   DoRop(_tmp, rop, src, _tmp) \
  419.   FASTPUTBITS(_tmp, x, w, pdst); \
  420. }
  421. #define putbitsrrop(src, x, w, pdst, rop) \
  422. { \
  423.   register int _tmp; \
  424.  \
  425.   FASTGETBITS(pdst, x, w, _tmp); \
  426.   _tmp= DoRRop(rop, src, _tmp); \
  427.   FASTPUTBITS(_tmp, x, w, pdst); \
  428. }
  429. #undef u_putbitsrop
  430. #endif
  431. #endif
  432.  
  433. #ifndef putbitsrop
  434. #define putbitsrop(src, x, w, pdst, rop)  u_putbitsrop(src, x, w, pdst, rop)
  435. #endif 
  436.  
  437. #ifndef putbitsrrop
  438. #define putbitsrrop(src, x, w, pdst, rop) \
  439. {\
  440.     register int t1, t2; \
  441.     register int n = (x)+(w)-32; \
  442.     \
  443.     t1 = SCRRIGHT((src), (x)); \
  444.     t2 = DoRRop(rop, t1, *(pdst)); \
  445.     \
  446.     if (n <= 0) \
  447.     { \
  448.     register int tmpmask; \
  449.     \
  450.     maskpartialbits((x), (w), tmpmask); \
  451.     *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
  452.     } \
  453.     else \
  454.     { \
  455.     int m = 32-(x); \
  456.     *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
  457.     t1 = SCRLEFT((src), m); \
  458.     t2 = DoRRop(rop, t1, (pdst)[1]); \
  459.     (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
  460.     } \
  461. }
  462. #endif
  463.  
  464. #if GETLEFTBITS_ALIGNMENT == 1
  465. #define getleftbits(psrc, w, dst)    dst = *((unsigned int *) psrc)
  466. #endif /* GETLEFTBITS_ALIGNMENT == 1 */
  467.  
  468. #if GETLEFTBITS_ALIGNMENT == 2
  469. #define getleftbits(psrc, w, dst) \
  470.     { \
  471.     if ( ((int)(psrc)) & 0x01 ) \
  472.         getbits( ((unsigned int *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
  473.     else \
  474.         getbits(psrc, 0, w, dst);
  475.     }
  476. #endif /* GETLEFTBITS_ALIGNMENT == 2 */
  477.  
  478. #if GETLEFTBITS_ALIGNMENT == 4
  479. #define getleftbits(psrc, w, dst) \
  480.     { \
  481.     int off, off_b; \
  482.     off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
  483.     getbits( \
  484.         (unsigned int *)( ((char *)(psrc)) - off), \
  485.         (off_b), (w), (dst) \
  486.            ); \
  487.     }
  488. #endif /* GETLEFTBITS_ALIGNMENT == 4 */
  489.  
  490.  
  491. #define getshiftedleftbits(psrc, offset, w, dst) \
  492.     getleftbits((psrc), (w), (dst)); \
  493.     dst = SCRLEFT((dst), (offset));
  494.  
  495. /* FASTGETBITS and FASTPUTBITS are not necessarily correct implementations of
  496.  * getbits and putbits, but they work if used together.
  497.  *
  498.  * On a MSBFirst machine, a cpu bitfield extract instruction (like bfextu)
  499.  * could normally assign its result to a long word register in the screen
  500.  * right position.  This saves canceling register shifts by not fighting the
  501.  * natural cpu byte order.
  502.  *
  503.  * Unfortunately, these fail on a 3/60+CG4 and cannot be used unmodified. Sigh.
  504.  */
  505. #if defined(FASTGETBITS) && defined(FASTPUTBITS)
  506. #ifdef NO_3_60_CG4
  507. #define u_FASTPUT(aa, bb, cc, dd)  FASTPUTBITS(aa, bb, cc, dd)
  508. #else
  509. #define u_FASTPUT(aa, bb, cc, dd)  u_putbits(SCRLEFT(aa, 32-(cc)), bb, cc, dd)
  510. #endif
  511.  
  512. #define getandputbits(psrc, srcbit, dstbit, width, pdst) \
  513. { \
  514.     register unsigned int _tmpbits; \
  515.     FASTGETBITS(psrc, srcbit, width, _tmpbits); \
  516.     u_FASTPUT(_tmpbits, dstbit, width, pdst); \
  517. }
  518.  
  519. #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
  520. { \
  521.   register unsigned int _tmpsrc, _tmpdst; \
  522.   FASTGETBITS(pdst, dstbit, width, _tmpdst); \
  523.   FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
  524.   DoRop(_tmpdst, rop, _tmpsrc, _tmpdst); \
  525.   u_FASTPUT(_tmpdst, dstbit, width, pdst); \
  526. }
  527.  
  528. #define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
  529. { \
  530.   register unsigned int _tmpsrc, _tmpdst; \
  531.   FASTGETBITS(pdst, dstbit, width, _tmpdst); \
  532.   FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
  533.   _tmpdst = DoRRop(rop, _tmpsrc, _tmpdst); \
  534.   u_FASTPUT(_tmpdst, dstbit, width, pdst); \
  535. }
  536.  
  537. #define getandputbits0(psrc, srcbit, width, pdst) \
  538.     getandputbits(psrc, srcbit, 0, width, pdst)
  539.  
  540. #define getandputrop0(psrc, srcbit, width, pdst, rop) \
  541.         getandputrop(psrc, srcbit, 0, width, pdst, rop)
  542.  
  543. #define getandputrrop0(psrc, srcbit, width, pdst, rop) \
  544.         getandputrrop(psrc, srcbit, 0, width, pdst, rop)
  545.  
  546.  
  547. #else /* Slow poke */
  548.  
  549. /* pairs of getbits/putbits happen frequently. Some of the code can
  550.  * be shared or avoided in a few specific instances.  It gets us a
  551.  * small advantage, so we do it.  The getandput...0 macros are the only ones
  552.  * which speed things here.  The others are here for compatibility w/the above
  553.  * FAST ones
  554.  */
  555.  
  556. #define getandputbits(psrc, srcbit, dstbit, width, pdst) \
  557. { \
  558.     register unsigned int _tmpbits; \
  559.     getbits(psrc, srcbit, width, _tmpbits); \
  560.     putbits(_tmpbits, dstbit, width, pdst); \
  561. }
  562.  
  563. #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
  564. { \
  565.     register unsigned int _tmpbits; \
  566.     getbits(psrc, srcbit, width, _tmpbits) \
  567.     putbitsrop(_tmpbits, dstbit, width, pdst, rop) \
  568. }
  569.  
  570. #define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
  571. { \
  572.     register unsigned int _tmpbits; \
  573.     getbits(psrc, srcbit, width, _tmpbits) \
  574.     putbitsrrop(_tmpbits, dstbit, width, pdst, rop) \
  575. }
  576.  
  577.  
  578. #define getandputbits0(psrc, sbindex, width, pdst) \
  579. {            /* unroll the whole damn thing to see how it * behaves */ \
  580.     register int          _flag = 32 - (sbindex); \
  581.     register unsigned int _src; \
  582.  \
  583.     _src = SCRLEFT (*(psrc), (sbindex)); \
  584.     if ((width) > _flag) \
  585.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  586.  \
  587.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  588. }
  589.  
  590.  
  591. #define getandputrop0(psrc, sbindex, width, pdst, rop) \
  592. {            \
  593.     register int          _flag = 32 - (sbindex); \
  594.     register unsigned int _src; \
  595.  \
  596.     _src = SCRLEFT (*(psrc), (sbindex)); \
  597.     if ((width) > _flag) \
  598.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  599.     DoRop(_src, rop, _src, *(pdst)); \
  600.  \
  601.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  602. }
  603.  
  604. #define getandputrrop0(psrc, sbindex, width, pdst, rop) \
  605. { \
  606.     int             _flag = 32 - (sbindex); \
  607.     register unsigned int _src; \
  608.  \
  609.     _src = SCRLEFT (*(psrc), (sbindex)); \
  610.     if ((width) > _flag) \
  611.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  612.     _src = DoRRop(rop, _src, *(pdst)); \
  613.  \
  614.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  615. }
  616.  
  617. #endif  /* FASTGETBITS && FASTPUTBITS */
  618. @
  619.